﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ITOMMS.Entity;
using Watson.Core.Tools;
using ITOMMS.Business;

namespace ITOMMS.Web.Main
{
    public partial class Satisfaction : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownListHelper.InitDropList<tbUserEntity>(new tbUserEntity().GetAllByQuery("RoleGroup=" + (int)PubEnums.RoleGroup.客户), ddlCompanyID, "ID", "CompanyName");//绑定公司
                ddlCompanyID.SelectedValue = SessionHelper.UserCompanyID.ToString();
                ddlCompanyID.Enabled = false;

                DropDownListHelper.InitDropList<tbContractServiceClassEntity>(new tbContractServiceClassEntity().GetAll(), ddlServiceType, "ID", "ClassName");//绑定服务类别
                //DropDownListHelper.InitDropList<tbTroubleServiceClassEntity>(new tbTroubleServiceClassEntity().GetAll(), ddlTroubleServiceClass, "ID", "ClassName");
                DropDownListHelper.InitDropList<tbUserEntity>(new tbUserEntity().GetAllByQuery("RoleGroup!=" + PubEnums.RoleGroup.客户.ToString("D")), ddlEngineer, "ID", "RealName");
                if (Request.QueryString["id"] != null)
                {
                    string strId = Request.QueryString["id"].ToString();
                    int id = 0;
                    if (int.TryParse(strId, out id))
                    {
                        dataBind(id);
                    }
                }
            }
        }


        private void dataBind(int id)
        {
            tbQuestionnaireEntity ask = new Entity.tbQuestionnaireEntity();
            ask = ask.GetById(id);
            if (ask != null)
            {
                ViewState["Entity"] = ask;
                this.ddlCompanyID.SelectedValue = ask.客户名称;
                txtCustomerPhone.Text = ask.客户电话;
                txtfeedback.Text = ask.反馈人;
                ddlEngineer.SelectedValue = ask.工程师.ToString();
                ddlServiceType.SelectedValue = ask.服务项目.ToString();


                if (ask.ASK1 == true)
                    this.r1a.Checked = true;
                else
                    this.r1b.Checked = true;

                if (ask.ASK2 == true)
                    this.r2a.Checked = true;
                else
                    this.r2b.Checked = true;

                if (ask.ASK3 == true)
                    this.r3a.Checked = true;
                else
                    this.r3b.Checked = true;

                if (ask.ASK4 == true)
                    this.r4a.Checked = true;
                else
                    this.r4b.Checked = true;

                if (ask.ASK5 == true)
                    this.r5a.Checked = true;
                else
                    this.r5b.Checked = true;

                if (ask.ASK6 == true)
                    this.r6a.Checked = true;
                else
                    this.r6b.Checked = true;

                if (ask.ASK7 == true)
                    this.r7a.Checked = true;
                else
                    this.r7b.Checked = true;

                if (ask.ASK8 == true)
                    this.r8a.Checked = true;
                else
                    this.r8b.Checked = true;

                if (ask.ASK9 == true)
                    this.r9a.Checked = true;
                else
                    this.r9b.Checked = true;

                if (ask.ASK10 == true)
                    this.r10a.Checked = true;
                else
                    this.r10b.Checked = true;

                if (ask.专业技术.ToString() == "1")
                    this.RadioButton1.Checked = true;
                else if (ask.专业技术.ToString() == "2")
                    this.RadioButton2.Checked = true;
                else if (ask.专业技术.ToString() == "3")
                    this.RadioButton3.Checked = true;
                else if (ask.专业技术.ToString() == "4")
                    this.RadioButton4.Checked = true;
                else
                    this.RadioButton5.Checked = true;

                if (ask.服务态度.ToString() == "1")
                    this.RadioButton6.Checked = true;
                else if (ask.服务态度.ToString() == "2")
                    this.RadioButton7.Checked = true;
                else if (ask.服务态度.ToString() == "3")
                    this.RadioButton8.Checked = true;
                else if (ask.服务态度.ToString() == "4")
                    this.RadioButton9.Checked = true;
                else
                    this.RadioButton10.Checked = true;

                if (ask.总体评价.ToString() == "1")
                    this.RadioButton11.Checked = true;
                else if (ask.总体评价.ToString() == "2")
                    this.RadioButton12.Checked = true;
                else if (ask.总体评价.ToString() == "3")
                    this.RadioButton13.Checked = true;
                else if (ask.总体评价.ToString() == "4")
                    this.RadioButton14.Checked = true;
                else
                    this.RadioButton15.Checked = true;

            }
        }





        protected void btnMore_ServerClick(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(txtCustomerName.Text))
            //{

            //    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.alert('客户名称不能为空。',300,180,'提示',null);</script>");
            //    return;
            //}


            if (ddlServiceType.SelectedValue == "-1")
            {

                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.alert('服务项目必须选择。',300,180,'提示',null);</script>");
                return;
            }
            if (ddlEngineer.SelectedValue == "-1")
            {

                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.alert('工程师必须选择。',300,180,'提示',null);</script>");
                return;
            }


            try
            {
                tbQuestionnaireEntity ask = new tbQuestionnaireEntity();
                if (ViewState["Entity"] != null && ViewState["Entity"] is tbQuestionnaireEntity)
                {
                    ask = ViewState["Entity"] as tbQuestionnaireEntity;
                }
                else
                {
                    ask.CreateBy = SessionHelper.UserID;
                    ask.CreateDate = DateTime.Now;
                }

                ask.客户名称 = this.ddlCompanyID.SelectedValue;
                ask.客户电话 = txtCustomerPhone.Text;
                ask.反馈人 = txtfeedback.Text;
                ask.工程师 = int.Parse(ddlEngineer.SelectedValue);
                ask.服务项目 = int.Parse(ddlServiceType.SelectedValue);

                if (r1a.Checked)
                {
                    ask.ASK1 = true;
                }
                else
                {
                    ask.ASK1 = false;
                }


                if (r2a.Checked)
                {
                    ask.ASK2 = true;
                }
                else
                {
                    ask.ASK2 = false;
                }


                if (r3a.Checked)
                {
                    ask.ASK3 = true;
                }
                else
                {
                    ask.ASK3 = false;
                }


                if (r4a.Checked)
                {
                    ask.ASK4 = true;
                }
                else
                {
                    ask.ASK4 = false;
                }


                if (r5a.Checked)
                {
                    ask.ASK5 = true;
                }
                else
                {
                    ask.ASK5 = false;
                }


                if (r6a.Checked)
                {
                    ask.ASK6 = true;
                }
                else
                {
                    ask.ASK6 = false;
                }


                if (r7a.Checked)
                {
                    ask.ASK7 = true;
                }
                else
                {
                    ask.ASK7 = false;
                }


                if (r8a.Checked)
                {
                    ask.ASK8 = true;
                }
                else
                {
                    ask.ASK8 = false;
                }


                if (r9a.Checked)
                {
                    ask.ASK9 = true;
                }
                else
                {
                    ask.ASK9 = false;
                }


                if (r10a.Checked)
                {
                    ask.ASK10 = true;
                }
                else
                {
                    ask.ASK10 = false;
                }


                if (RadioButton1.Checked)
                {
                    ask.专业技术 = 1;
                }
                else if (RadioButton2.Checked)
                {
                    ask.专业技术 = 2;
                }
                else if (RadioButton3.Checked)
                {
                    ask.专业技术 = 3;
                }
                else if (RadioButton4.Checked)
                {
                    ask.专业技术 = 4;
                }
                else if (RadioButton5.Checked)
                {
                    ask.专业技术 = 5;
                }



                if (RadioButton6.Checked)
                {
                    ask.服务态度 = 1;
                }
                else if (RadioButton7.Checked)
                {
                    ask.服务态度 = 2;
                }
                else if (RadioButton8.Checked)
                {
                    ask.服务态度 = 3;
                }
                else if (RadioButton9.Checked)
                {
                    ask.服务态度 = 4;
                }
                else if (RadioButton10.Checked)
                {
                    ask.服务态度 = 5;
                }




                if (RadioButton11.Checked)
                {
                    ask.总体评价 = 1;
                }
                else if (RadioButton12.Checked)
                {
                    ask.总体评价 = 2;
                }
                else if (RadioButton13.Checked)
                {
                    ask.总体评价 = 3;
                }
                else if (RadioButton14.Checked)
                {
                    ask.总体评价 = 4;
                }
                else if (RadioButton15.Checked)
                {
                    ask.总体评价 = 5;
                }



                ask.SaveOrUpdate();
                ViewState["Entity"] = ask;

                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.succeedInfo('满意度评价成功。',300,180,'提示',null);</script>");
             }
            catch (Exception ex)
            {
                log4netHelper.error("满意度评价失败", ex);
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>ymPrompt.errorInfo('满意度评价失败。',300,180,'提示',null);</script>");
            }
        }
    }
}
